import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import IndexRouter from './routes';
import registerServiceWorker from './registerServiceWorker';

// redux
// 引入redux
import { Provider } from 'react-redux';
import reduxThunk from 'redux-thunk';
import {createStore, applyMiddleware} from 'redux';

// 引入reducer
import AppReducer from './reducers';
import { AUTH_USER } from './actions/types'

const createStoreWithMiddleware = applyMiddleware(reduxThunk)(createStore)
const store = createStoreWithMiddleware(AppReducer)
const tokenInfo = localStorage.getItem('token')

if (tokenInfo) {
    store.dispatch({type: AUTH_USER, payload: JSON.parse(tokenInfo)})
}

ReactDOM.render(
    <Provider store={store}>
        <IndexRouter />
    </Provider>,
    document.getElementById('root'));

registerServiceWorker();
